package com.cskaoyan.service;

import com.cskaoyan.bean.pojo.Feedback;
import com.cskaoyan.bean.pojo.User;
import com.cskaoyan.bean.wxbo.WxFeedbackBo;
import com.cskaoyan.mapper.FeedbackMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

@Service
@Transactional(rollbackFor = Exception.class)
public class WxFeedbackServiceImpl implements WxFeedbackService {
    @Autowired
    FeedbackMapper feedbackMapper;
    @Override
    public int feedbackSubmit(WxFeedbackBo wxFeedbackBo, User user) {
        Feedback feedback = new Feedback ();
        feedback.setUserId (user.getId ())
                .setUsername (user.getUsername ())
                .setMobile (wxFeedbackBo.getMobile ())
                .setFeedType (wxFeedbackBo.getFeedType ())
                .setContent (wxFeedbackBo.getContent ())
                .setStatus (0)
                .setAddTime (new Date ())
                .setUpdateTime (new Date ())
                .setDeleted (false);
        if (wxFeedbackBo.isHasPicture ()) {
            feedback.setHasPicture (true)
                    .setPicUrls (wxFeedbackBo.getPicUrls ().toString ());
        } else feedback.setHasPicture (false);
        int i = feedbackMapper.insertSelective (feedback);
        return i;
    }
}
